# coding=utf-8
import os
import json

from jproperties import Properties

from tools import convert, globalvar
from tools.properties import PropertiesUtils
from webapp.config import Config


class StoreInfo:
    def saveStoreInfo(self, data):

        if len(data) > 0:
            # 获取路径
            filename = Config.ROOT_PATH + os.sep + r"initconfig" + os.sep + "master.properties"
            PropertiesUtils().saveProperties(filename, Config.KEY_STORE, data)

    def getStoreInfo(self):

        storeobject = globalvar.get_storeobject()
        # print("getStoreInfo1 " + str(storeobject))
        if storeobject == {}:
            filename = Config.ROOT_PATH + os.sep + r"initconfig" + os.sep + "master.properties"
            print(filename)
            storeobject = PropertiesUtils().getProperties(filename, Config.KEY_STORE)
            globalvar.set_storeobject(storeobject)

        print("getStoreInfo3 " + str(storeobject))

        return storeobject


if __name__ == "__main__":
    s = StoreInfo()
    arrs = s.getStoreInfo()
    print(arrs)
    storeID = arrs.get("CP_C_STORE_ID", "")
    print(type(arrs))

    arrs = s.getStoreInfo()
    print(arrs)
    storeID = arrs.get("CP_C_STORE_ID", "")

    # arr = arrs["STORE"]
    print(type(arrs))

    # print(decode_json["CHECK_STATUS"])
    # cpuRegist.getStoreInfo();
